﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.Unity;
using System.Web.ModelBinding;
using ddcCajamarca.BusinessEntities.Directorio;
using ddcCajamarca.BusinessLogic.Directorio.Service;

namespace ddcCajamarca.Web.Directorio
{
    public partial class frmProfesion : System.Web.UI.Page
    {
        [Dependency]
        public IProfesionBL profesionBL { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {
            var accion = Request.QueryString["accion"];
            var id = Request.QueryString["id"];
            if (accion != null && accion == "nuevo")
            {
                fvProfesion.DefaultMode = FormViewMode.Insert;
            }
            else if (accion != null && id != null && accion == "delete")
            {
                Int32 idprofesion = Int32.Parse(id);

                profesionBL.DeleteProfesion(idprofesion);
                Response.Redirect("frmListProfesion.aspx");
            }
        }

        public Profesion GetProfesion([QueryString("id")] Int32? id)
        {
            if (id.HasValue)
                return profesionBL.GetFromProfesionById(id.Value);
            return null;
        }

        public void UpdateProfesion(Profesion profesion)
        {

            if (ModelState.IsValid)
                profesionBL.UpdateProfesion(profesion);
            Response.Redirect("frmListProfesion.aspx");
        }

        public void InsertProfesion(Profesion profesion)
        {
            if (ModelState.IsValid)
            {
                profesionBL.AddProfesion(profesion);
            }
            Response.Redirect("frmListProfesion.aspx");

        }
    }
}